package com.iraeta.controller.page;

import com.alibaba.fastjson.JSONObject;
import com.iraeta.common.AuthAccess;
import com.iraeta.controller.BaseController;
import com.iraeta.service.page.SalServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@RestController(value = "SalController")
@RequestMapping("sal")
public class SalController extends BaseController {
    @Autowired
    SalServiceImpl salService;

    @RequestMapping("listsomain")
    @AuthAccess
    public String listSoMain(@RequestBody JSONObject jo){
        String csocode = jo.getString("csocode") != null ? jo.getString("csocode").trim() : null;
        String cinvname = jo.getString("cinvname") != null ? jo.getString("cinvname").trim() : null;
        String ccusname = jo.getString("ccusname") != null ? jo.getString("ccusname").trim() : null;
        List<HashMap<String, Object>> res = salService.listSoMain(csocode, cinvname, ccusname);
        if(res == null || res.size() == 0){
            return this.error("数据不存在");
        }else{
            return this.success(res);
        }
    }

    @RequestMapping("listgqsomain")
    @AuthAccess
    public String listGqSoMain(@RequestBody JSONObject jo){
        String csocode = jo.getString("csocode") != null ? jo.getString("csocode").trim() : null;
        String cinvname = jo.getString("cinvname") != null ? jo.getString("cinvname").trim() : null;
        String ccusname = jo.getString("ccusname") != null ? jo.getString("ccusname").trim() : null;
        List<HashMap<String, Object>> res = salService.listGqSoMain(csocode, cinvname, ccusname);
        if(res == null || res.size() == 0){
            return this.error("数据不存在");
        }else{
            return this.success(res);
        }
    }
}
